#include "LcData.h"

#include <float.h>
#include <limits.h>

#include "ComDefine.h"

bool CLcData::IsCommNormal()
{
    return (0 == m_uCommState);
}

bool CLcData::IsCommFault()
{
    return (1 == m_uCommState);
}

bool CLcData::IsRunning()
{
    return (0 == m_uRunState);
}

bool CLcData::IsStopped()
{
    return (1 == m_uRunState);
}

bool CLcData::IsFault()
{
    return (1 == m_uFaultState);
}

bool CLcData::IsNoFault()
{
    return (0 == m_uFaultState);
}

bool CLcData::IsAlarm()
{
    return (1 == m_uAlarmState);
}

bool CLcData::IsNoAlarm()
{
    return (0 == m_uAlarmState);
}

bool CLcData::IsOpening()
{
    return (1 == m_uSwitchState);
}

bool CLcData::IsClosed()
{
    return (0 == m_uSwitchState);
}

//获取***的显示文本
QString CLcData::GetCommStateText()
{
    if (0xFFFF == m_uCommState)
    {
        return QObject::tr("---");
    }
    else if (1 == m_uCommState)
    {
        return QObject::tr("故障");
    }
    else
    {
        return QObject::tr("正常");
    }
}

void CLcData::InitToInvalid()
{
    InitToValue(0xFFFF, FLT_MAX);
}

void CLcData::InitToZero()
{
    InitToValue(0, 0.0);
}

void CLcData::InitToValue(quint16 uvalue, float fvalue)
{
    m_uCommState = uvalue;
    for (int i = 0; i < ARRAYSIZE(m_uRev); ++i)
    {
        m_uRev[i] = uvalue;
    }
    for (int i = 0; i < ARRAYSIZE(m_fRev); ++i)
    {
        m_fRev[i] = fvalue;
    }

    //转发的100个UINT16数据
    m_uRunState = uvalue;
    m_uFaultState = uvalue;
    m_uAlarmState = uvalue;
    m_uSwitchState = uvalue;
    m_uWorkState = uvalue;

    m_uFaultCode = uvalue;
    m_uEngineSpeed = uvalue;
    m_uPumpSpeed = uvalue;
    m_uDebugState = uvalue;
    m_uAlarmCode1 = uvalue;

    m_uAlarmCode2 = uvalue;
    m_uAlarmCode3 = uvalue;
    m_uAlarmCode4 = uvalue;
    m_uAlarmCode5 = uvalue;
    m_uAlarmCode6 = uvalue;

    m_uFaultCode1 = uvalue;
    m_uFaultCode2 = uvalue;
    m_uFaultCode3 = uvalue;
    m_uFaultCode4 = uvalue;
    m_uFaultCode5 = uvalue;

    m_uFaultCode6 = uvalue;
    m_uPumpState1 = uvalue;
    m_uPumpState2 = uvalue;
    m_uPumpState3 = uvalue;
    m_uPumpState4 = uvalue;
    m_uPumpState5 = uvalue;

    m_uCoolerState1 = uvalue;
    m_uCoolerState2 = uvalue;
    m_uCoolerState3 = uvalue;
    m_uCoolerState4 = uvalue;
    m_uCoolerState5 = uvalue;

    m_uSupplyWaterState = uvalue;
    m_uRemoteState = uvalue;
    m_uAlarmLevel = uvalue;
    m_uMachineEnable = uvalue;
    m_uTempControlMode = uvalue;
    m_uRemoteEnable = uvalue;        //远程使能,0禁用/未启用;1未禁用/启用
    m_uBootDelayTimes = uvalue;      //自启动延时时间
    m_uAutoStartAfterPower = uvalue; //来电自启动
    m_uManualDebug = uvalue;         //手动调机

    m_uRunnedYears = uvalue;         //已运行的年数
    m_uRunnedMonths = uvalue;        //已运行的月数
    m_uRunnedDays = uvalue;          //已运行的天数
    m_uRunnedHours = uvalue;         //已运行的小时数
    m_uRunnedMinutes = uvalue;       //已运行的分钟数

    m_uRunnedSeconds = uvalue;       //已运行的秒数
    m_uBatChgDchgState = uvalue;     //电池的充放电状态
    for (int i = 0; i < ARRAYSIZE(m_uData); ++i)
    {
        m_uData[i] = uvalue;
    }

    //转发的100个FLOAT数据
    m_fOutWaterTemp = fvalue;
    m_fInWaterTemp = fvalue;
    m_fOutWaterPres = fvalue;
    m_fInWaterPres = fvalue;
    m_fEnvTemp = fvalue;

    m_fCoolStartTemp = fvalue;
    m_fCoolStopTemp = fvalue;
    m_fCoolDiffTemp = fvalue;
    m_fHeatStartTemp = fvalue;
    m_fHeatStopTemp = fvalue;

    m_fHeatDiffTemp = fvalue;
    m_fDryStartHumi = fvalue;
    m_fDryStopHumi = fvalue;
    m_fDryDiffHumi = fvalue;
    m_fDebugSglMaxTemp = fvalue;

    m_fDebugSglMinTemp = fvalue;
    m_fDebugSglAvgTemp = fvalue;
    m_fDebugSglMaxTempDiff = fvalue;
    m_fVentilateTemp = fvalue;
    m_fAcCur = fvalue;

    m_fAcVol = fvalue;
    m_fDcCur = fvalue;
    m_fDcVol = fvalue;
    m_fCoolFlow = fvalue;
    m_fOutSteamTemp = fvalue;

    m_fInSteamTemp = fvalue;
    m_fMaxTempAlarm = fvalue;          // 高温告警点/液温过高点
    m_fMinTempAlarm = fvalue;          // 低温告警点/液温过低点
    m_fMaxHumiAlarm = fvalue;          // 高湿告警点
    m_fMinHumiAlarm = fvalue;          // 低湿告警点

    m_fOutWaterPresMaxAlarm = fvalue;  //供水压力过高点
    m_fOutWaterPresMinAlarm = fvalue;  //供水压力过低点
    m_fInWaterPresMaxAlarm = fvalue;   //回水压力过高点
    m_fInWaterPresMinAlarm = fvalue;   //回水压力过低点
    m_fFixTempTargetValue = fvalue;    //恒温方式预设温度,单位为℃

    m_fOutSteamTemp2 = fvalue;          //蒸出温度2,单位为℃
    m_fOutSteamTemp3 = fvalue;          //蒸出温度3,单位为℃
    m_fOutSteamTemp4 = fvalue;          //蒸出温度4,单位为℃
    m_fOutSteamTemp5 = fvalue;          //蒸出温度5,单位为℃
    m_fOutSteamTemp6 = fvalue;          //蒸出温度6,单位为℃

    m_fInSteamTemp2 = fvalue;           //蒸进温度2,单位为℃
    m_fInSteamTemp3 = fvalue;           //蒸进温度3,单位为℃
    m_fInSteamTemp4 = fvalue;           //蒸进温度4,单位为℃
    m_fInSteamTemp5 = fvalue;           //蒸进温度5,单位为℃
    m_fInSteamTemp6 = fvalue;           //蒸进温度6,单位为℃

    m_fBatMaxTemp = fvalue;            //电池电芯最高温度,单位为℃
    m_fBatMinTemp = fvalue;            //电池电芯最低温度,单位为℃
    m_fBatAvgTemp = fvalue;            //电池电芯平均温度,单位为℃
    m_fEnvTemp2 = fvalue;               //环境温度2,单位为℃
    m_fEnvTemp3 = fvalue;               //环境温度3,单位为℃

    m_fEnvTemp4 = fvalue;               //环境温度4,单位为℃
    m_fEnvTemp5 = fvalue;               //环境温度5,单位为℃
    m_fEnvTemp6 = fvalue;               //环境温度6,单位为℃
    for (int i = 0; i < ARRAYSIZE(m_fData); ++i)
    {
        m_fData[i] = fvalue;
    }

    m_fSetCoolStartTemp = fvalue;
    m_fSetCoolStartTempCopy = fvalue;
    m_fSetCoolStopTemp = fvalue;
    m_fSetCoolStopTempCopy = fvalue;
    m_fSetCoolDiffTemp = fvalue;
    m_fSetCoolDiffTempCopy = fvalue;
    m_fSetHeatStartTemp = fvalue;
    m_fSetHeatStartTempCopy = fvalue;
    m_fSetHeatStopTemp = fvalue;
    m_fSetHeatStopTempCopy = fvalue;
    m_fSetHeatDiffTemp = fvalue;
    m_fSetHeatDiffTempCopy = fvalue;
    m_fSetDryStartHumi = fvalue;
    m_fSetDryStartHumiCopy = fvalue;
    m_fSetDryStopHumi = fvalue;
    m_fSetDryStopHumiCopy = fvalue;
    m_fSetDryDiffHumi = fvalue;
    m_fSetDryDiffHumiCopy = fvalue;
    m_fSetTargetTemp = fvalue;
    m_fSetTargetTempCopy = fvalue;
    m_fSetTargetCheckTemp = fvalue;
    m_fSetTargetCheckTempCopy = fvalue;
    m_fSetMonitorMaxTemp = fvalue;         //20817 监控下发最大温度,单位为℃
    m_fSetMonitorMaxTempCopy = fvalue;
    m_fSetMonitorMinTemp = fvalue;         //20818 监控下发最小温度,单位为℃
    m_fSetMonitorMinTempCopy = fvalue;
    m_fSetMonitorAvgTemp = fvalue;         //20819 监控下发平均温度,单位为℃
    m_fSetMonitorAvgTempCopy = fvalue;
    m_fSetMaxTempAlarm = fvalue;           //下设高温告警点/液温过高点
    m_fSetMaxTempAlarmCopy = fvalue;

    m_fSetMinTempAlarm = fvalue;          //下设低温告警点/液温过低点
    m_fSetMinTempAlarmCopy = fvalue;
    m_fSetMaxHumiAlarm = fvalue;          //下设高湿告警点
    m_fSetMaxHumiAlarmCopy = fvalue;
    m_fSetMinHumiAlarm = fvalue;          //下设低湿告警点
    m_fSetMinHumiAlarmCopy = fvalue;
    m_fSetOutWaterPresMaxAlarm = fvalue;   //下设供水压力过高点
    m_fSetOutWaterPresMaxAlarmCopy = fvalue;
    m_fSetOutWaterPresMinAlarm = fvalue;   //下设供水压力过低点
    m_fSetOutWaterPresMinAlarmCopy = fvalue;

    m_fSetInWaterPresMaxAlarm = fvalue;   //下设回水压力过高点
    m_fSetInWaterPresMaxAlarmCopy = fvalue;
    m_fSetInWaterPresMinAlarm = fvalue;   //下设回水压力过低点
    m_fSetInWaterPresMinAlarmCopy = fvalue;
    m_fSetFixTempTargetValue = fvalue;    //下设恒温方式预设温度,单位为℃
    m_fSetFixTempTargetValueCopy = fvalue;
    m_fSetEngineSpeed = fvalue;            //下设液冷压缩机转速
    m_fSetEngineSpeedCopy = fvalue;
    m_fSetPumpSpeed = fvalue;              //下设液冷水泵转速
    m_fSetPumpSpeedCopy = fvalue;

    m_fSetBatMaxTemp = fvalue;             //下设电池电芯最高温度,单位为℃
    m_fSetBatMaxTempCopy = fvalue;
    m_fSetBatMinTemp = fvalue;             //下设电池电芯最低温度,单位为℃
    m_fSetBatMinTempCopy = fvalue;
    m_fSetBatAvgTemp = fvalue;             //下设电池电芯平均温度,单位为℃
    m_fSetBatAvgTempCopy = fvalue;
    for (int i = 0; i < ARRAYSIZE(m_fSetData); ++i)
    {
        m_fSetData[i] = fvalue;
    }

    for (int i = 0; i < ARRAYSIZE(m_fSetDataCopy); ++i)
    {
        m_fSetDataCopy[i] = fvalue;
    }

    m_uSetWorkState = uvalue;
    m_uSetWorkStateCopy = uvalue;
    m_uSetSwitch = uvalue;
    m_uSetSwitchCopy = uvalue;
    m_uSetControlMode = uvalue;
    m_uSetControlModeCopy = uvalue;
    m_uSetMachineEnable = uvalue;
    m_uSetMachineEnableCopy = uvalue;
    m_uSetTempControlMode = uvalue;
    m_uSetTempControlModeCopy = uvalue;
    m_uSetRemoteState = uvalue;         //下设远程状态:0本地,1远程
    m_uSetRemoteStateCopy = uvalue;
    m_uSetRemoteEnable = uvalue;        //下设远程使能:0禁用/未启用;1未禁用/启用
    m_uSetRemoteEnableCopy = uvalue;
    m_uSetBootDelayTimes = uvalue;      //下设自启动延时时间
    m_uSetBootDelayTimesCopy = uvalue;
    m_uSetFaultReset = uvalue;           //设置故障复位:0不动作,1故障复位
    m_uSetFaultResetCopy = uvalue;
    m_uSetAutoStartAfterPower = uvalue;  //设置来电自启动
    m_uSetAutoStartAfterPowerCopy = uvalue;

    m_uSetManualDebug = uvalue;         //设置手动调机
    m_uSetManualDebugCopy = uvalue;
    m_uSetBatChgDchgState = uvalue;     //设置电池的充放电状态
    m_uSetBatChgDchgStateCopy = uvalue;
    for (int i = 0; i < ARRAYSIZE(m_uSetData); ++i)
    {
        m_uSetData[i] = uvalue;
    }

    for (int i = 0; i < ARRAYSIZE(m_uSetDataCopy); ++i)
    {
        m_uSetDataCopy[i] = uvalue;
    }
}
